import json
from vulcanus.log.log import LOGGER
from zeus.operation_service.app.proxy.asset import AssetProxy
from zeus.operation_service.app.core.framework.common.constant import TaskType
from zeus.operation_service.app.core.framework.task.task_detail.task_detail import TaskDetail


class HealthCheckDetail(TaskDetail):

    def __init__(self, validated_data):
        super().__init__(validated_data)
        self.task_type = TaskType.HEALTH_CHECK

    def generate_asset_items_info(self, asset):
        LOGGER.warning(f"get {self.task_type}_items begin")
        asset_items_list = list()
        asset_items = AssetProxy().get_asset_item(asset.asset_id, self.task_type)
        for asset_item in asset_items:
            asset_item_info = dict()
            asset_item_info['id'] = asset_item.item_id
            asset_item_info['item_path'] = asset_item.item_path
            item_detail = json.loads(asset_item.item_detail)
            item_name = dict()
            item_name['zh'] = item_detail['description']['des_zh']['@value']
            item_name['en'] = item_detail['description']['des_en']['@value']
            item_description = dict()
            item_description['zh'] = item_detail['details']['detail_zh']['@value']
            item_description['en'] = item_detail['details']['detail_en']['@value']
            asset_item_info['item_name'] = item_name
            asset_item_info['item_description'] = item_description
            asset_items_list.append(asset_item_info)
        return asset_items_list
